package com.ruoyi.web.controller.limiter;

import com.ruoyi.common.annotation.RateLimiter;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.LimitType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Redis接口限流Controller测试
 */
@RestController
public class RedisLimitController {

    protected Logger logger = LoggerFactory.getLogger(RedisLimitController.class);

    @RateLimiter
    @GetMapping("/test1")
    public R test1() {
        logger.info("【test1】被执行了。。。。。");
        return R.ok("成功访问到api [1]~");
    }

    @RateLimiter(
            count = 5,
            limitType = LimitType.IP,
            time = 60)
    @GetMapping("/test2")
    public R test2() {
        logger.info("【test2】被执行了。。。。。");
        return R.ok("成功访问到api [2]~");
    }

    @RateLimiter(
            count = 5,
            limitType = LimitType.IP,
            time = 60)
    @GetMapping("/test3")
    public R test3() {
        logger.info("【test3】被执行了。。。。。");
        return R.ok("成功访问到api [3]~");
    }
}
